package com.ylbh.modules.banner.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.activity.dto.GoodsListDTO;
import com.ylbh.common.pojo.banner.dto.BannerListDTO;
import com.ylbh.common.pojo.banner.dto.GoodsCommendAddDTO;
import com.ylbh.common.pojo.banner.dto.GoodsCommendDTO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.banner.entity.AppHomeBanner;
import com.ylbh.modules.banner.service.AppHomeBannerService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;

/**
 * @author czx
 * 专题管理
 */
@RestController
@RequestMapping("special")
public class HomeSpecialController {

    @Autowired
    private AppHomeBannerService appHomeBannerService;

    @ApiOperation("专题管理列表")
    @RequestMapping("querySpecialList")
    @RequiresPermissions("special:querySpecialList")
    public CommonResult<PageUtils> querySpecialList(BannerListDTO bannerListDTO) {
        PageUtils list = appHomeBannerService.querySpecialList(bannerListDTO);
        return Ref.ok(list);
    }

    @SysLog("修改专题管理列表")
    @ApiOperation("修改专题管理列表")
    @RequestMapping("modifySpecialDetails")
    @RequiresPermissions("special:modifySpecialDetails")
    public CommonResult<Void> modifySpecialDetails(@RequestBody AppHomeBanner appHomeBanner) {
        appHomeBanner.setBannerType("6");
        appHomeBanner.setAddTime(new Date());
        appHomeBannerService.updateById(appHomeBanner);
        return Ref.ok();
    }

    @SysLog("新增专题管理列表")
    @ApiOperation("新增专题管理列表")
    @RequestMapping("addSpecialDetails")
    @RequiresPermissions("special:addSpecialDetails")
    public CommonResult<Void> addSpecialDetails(@RequestBody AppHomeBanner appHomeBanner) {
        appHomeBanner.setBannerType("6");
        appHomeBanner.setAddTime(new Date());
        appHomeBanner.setShowStatus(1);
        appHomeBannerService.save(appHomeBanner);
        return Ref.ok();
    }

    @ApiOperation("商品推荐详情")
    @GetMapping("getGoodsRecommendInfoById/{id}")
    public CommonResult getGoodsRecommendInfoById(@PathVariable Integer id) {
        AppHomeBanner banner = appHomeBannerService.getGoodsRecommendInfoById(id);
        return Ref.ok(banner);
    }

    @SysLog("修改商品推荐详情")
    @ApiOperation("修改商品推荐详情")
    @PostMapping("modifyGoodsRecommendDetailsById")
    public CommonResult modifyGoodsRecommendDetailsById(@RequestBody GoodsCommendDTO goodsCommendDTO) {
        appHomeBannerService.modifyGoodsRecommendDetailsById(goodsCommendDTO);
        return Ref.ok();
    }

    @SysLog("新增商品推荐")
    @ApiOperation("新增商品推荐")
    @PostMapping("addGoodsCommend")
    @RequiresPermissions("special:addSpecialDetails")
    public CommonResult addGoodsCommend(@RequestBody AppHomeBanner appHomeBanner) {
        appHomeBannerService.addGoodsCommend(appHomeBanner);
        return Ref.ok();
    }

    @ApiOperation("商品推荐添加商品查询")
    @GetMapping("queryNotAddedGoods")
    public CommonResult queryNotAddedGoods(GoodsCommendAddDTO goodsListDTO) {
        PageUtils page = appHomeBannerService.queryNotAddedGoods(goodsListDTO);
        return Ref.ok(page);
    }
}
